﻿@model  IList<AdminUserModel>
@{
    ViewBag.Title = "用户管理";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<div class="path mb15">
    当前位置:<span>首页 &gt; </span><span>帐户管理 &gt; </span><span>用户管理</span>
</div>
<form id="GetForm" name="GetForm" method="get" onclick="return checkQuery()">
<div>
    <table class="tb-search mb10">
            <tr>
                <td>
                    创建日期：
                </td>
                <td class="box">
                    从&nbsp;&nbsp;<input name="txtBeginDate" id="txtBeginDate" style="width: 80px" value="@ViewBag.BeginDate"
                        class="input-style-d" readonly="readonly" onkeydown="if(event.keyCode == 8)this.value = '';return false;" />
                    &nbsp;&nbsp;到&nbsp;&nbsp;
                    <input name="txtEndDate" id="txtEndDate" style="width: 80px" value="@ViewBag.EndDate"
                        class="input-style-d" readonly="readonly" onkeydown="if(event.keyCode == 8)this.value = '';return false;" />
                </td>
                <td>
                    姓名：
                </td>
                <td class="box">
                    <input name="txtTrueName" value="@ViewBag.TrueName" class="input-style-d" />
                </td>
                <td>
                    登录账号：
                </td>
                <td class="box">
                    <input name="txtUserName" value="@ViewBag.UserName" class="input-style-d" />
                </td>
                <td class="box">
                    <input type="submit" value="搜索" class="i-btn1" />
                    &nbsp;
                    <input type="button" value="新增" class="i-btn1" onclick="location='/account/add';" />
                </td>
            </tr>
        </table>
</div>
<div>
    <table class="tb-data">
        <thead>
            <tr>
                <th>
                    编号
                </th>
                <th>
                    登录名
                </th>
                <th>
                    姓名
                </th>
                <th>
                    邮箱
                </th>
                <th>
                    电话
                </th>
                <th>
                    最后登录
                </th>
                <th>
                    创建时间
                </th>
                <th width="20%">
                    操作
                </th>
            </tr>
        </thead>
        <tbody>
            @if (Model != null)
            {

                foreach (var item in Model)
                { 
                <tr>
                    <td style="wid1th: 10%">
                        @item.UserID
                    </td>
                    <td style="wid1th: 20%">
                        @item.UserName
                    </td>
                    <td style="width: 20%">
                        @item.TrueName
                    </td>
                    <td style="width: 15%">
                        @item.EMail
                    </td>
                    <td style="width: 10%">
                        @item.Telephone
                    </td>
                    <td style="width: 10%">
                        @item.LastLoginTime
                    </td>
                    <td style="width: 10%">
                        @item.CreateTime
                    </td>
                    <td>
                        <a href="javascript:void(0);" onclick="Detail('@(item.UserID)')" name="view">查看</a>&nbsp;&nbsp;
                        <a href="/AdminUser/edit?userID=@(item.UserID)" name="edit">编辑</a>&nbsp;&nbsp;
                        <a href="javascript:;" onclick="SetRole('@(item.UserID)');" name="role">权限</a>&nbsp;&nbsp;
                        <a href="javascript:void(0);" onclick="Disable('@(item.UserID)')" name="delete">删除</a>
                    </td>
                </tr>
                }
            }
        </tbody>
    </table>
    <!-- 分页插件  -->
    <div id="pager" class="aR mt10">
    </div>
</div>
@if (Model != null)
{
    var pagerModel = @ViewBag.PagerModel as PagerModel;
    pagerModel.GetForm = "GetForm";
    Html.RenderPartial("PagerExControl", pagerModel);
}
else
{
    <span>没有找到您需要的搜索结果,请检查您的搜索条件!</span>
}
</form>
<script type="text/javascript">
    function checkQuery() {

        var t = 0;
        if ($('#txtBeginDate').val() != "") t++;
        if ($('#txtEndDate').val() != "") t++;

        if (t == 1) {
            alert("请将查询日期输入完整");
            return false;
        }
        return true;
    }

    function Detail(id) {
        OpenPop({
            page: '/Account/Detail?accountID=' + id,
            title: '查看账号',
            width: 450,
            height: 550
        });
    }

    function Edit(id) {
        OpenPop({
            page: '/Account/Edit?accountID=' + id,
            title: '选择关联账号',
            width: 450,
            height: 550
        });

    }

    (function () {
        //日期
        var dates = $('#txtBeginDate, #txtEndDate').datepicker({
            onSelect: function (selectedDate) {
                var option = this.id == "txtBeginDate" ? "minDate" : "maxDate",
				            instance = $(this).data("datepicker"),
				            date = $.datepicker.parseDate(
					            instance.settings.dateFormat ||
					            $.datepicker._defaults.dateFormat,
					            selectedDate, instance.settings
				            );
                dates.not(this).datepicker("option", option, date);
            }
        });
    })();

    // 删除即禁用
    function Disable(id) {
        OpenConfirm("提示", "您确定要将这条数据删除吗?", function () {

            $.ajax({
                url: "/account/disable?accountID=" + id,
                type: "POST",
                success: function (data) {
                    if (data.status == "error" || data.status == "warning") {
                        alert(data.msg);
                        return false;
                    }
                    alert(data.msg);
                    location = location;
                }
            })
        });
    }

    function Allow(id) {
        $("#accountID").val(id)
        GetForm.action = "/Account/Allow";
        GetForm.submit();
    }

    // 2012-4-25 陈炎明
    // 设置权限
    function SetRole(id) {
        OpenPop({
            page: '/AccountPermission/Edit?accountID=' + id,
            title: '设置权限',
            width: 950,
            height: 500
        });
    }        
</script>
